package cur.nature.framework.core.util;

import javax.sql.rowset.serial.SerialBlob;
import javax.sql.rowset.serial.SerialClob;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class ConvertUtil {
    public static final int UNASSIGNED_NULL = 0;
    public static final int ASSIGNED_NULL = 1;
    public static final int BYTE = 2;
    public static final int SHORT = 3;
    public static final int INT = 4;
    public static final int LONG = 5;
    public static final int FLOAT = 6;
    public static final int DOUBLE = 7;
    public static final int BIGINTEGER = 8;
    public static final int BIGDECIMAL = 10;
    public static final int BOOLEAN = 11;
    public static final int INPUTSTREAM = 12;
    public static final int DATE = 13;
    public static final int TIME = 14;
    public static final int TIMESTAMP = 15;
    public static final int STRING = 16;
    public static final int OBJECT = 17;
    public static final int BYTE_ARRAY = 18;
    public static final int BLOB = 19;
    public static final int CLOB = 20;
    public static final int ENUM = 21;
    public static final String ASSIGNEDNULL_S = "ASSIGNED_NULL";
    public static final String UNASSIGNEDNULL_S = "UNASSIGNED_NULL";
    public static final String BYTETYPE_S = "BYTE";
    public static final String SHORTTYPE_S = "SHORT";
    public static final String INTTYPE_S = "INT";
    public static final String INTEGERTYPE_S = "INTEGER";
    public static final String BIGINTEGERTYPE_S = "BIGINTEGER";
    public static final String LONGTYPE_S = "LONG";
    public static final String FLOATTYPE_S = "FLOAT";
    public static final String DOUBLETYPE_S = "DOUBLE";
    public static final String BIGDECIMALTYPE_S = "BIGDECIMAL";
    public static final String BOOLEANTYPE_S = "BOOLEAN";
    public static final String INPUTSTREAMTYPE_S = "INPUTSTREAM";
    public static final String DATETYPE_S = "DATE";
    public static final String TIMETYPE_S = "TIME";
    public static final String TIMESTAMPTYPE_S = "TIMESTAMP";
    public static final String BYTEARRAYTYPE_S = "[B";
    public static final String STRINGTYPE_S = "STRING";
    public static final String OBJECTTYPE_S = "OBJECT";
    public static final String BLOB_S = "SERIALBLOB";
    public static final String CLOB_S = "SERIALCLOB";
    public static final Double ZERODOUBLE = 0.0;
    public static final Float ZEROFLOAT = 0.0F;
    public static final String ZEROSTRING = "0";
    public static final String FALSESTRING = "false";
    public static final String NOTSUPPORTTYPECAST = "不支持的类型转换";
    public static final char PACKAGESEP = '.';
    public static final BigDecimal ZEROBIGDECIMAL = new BigDecimal(0);
    public static final byte[] EMPTYBYTES = new byte[0];
    public static final char[] EMPTYCHARS = new char[0];
    private static Map<String, String> types = new HashMap();
    static Map typeMap;

    static {
        types.put("BIGDECIMAL", String.valueOf(10));
        types.put("BOOLEAN", String.valueOf(11));
        types.put("[B", String.valueOf(18));
        types.put("BYTE", String.valueOf(2));
        types.put("DATE", String.valueOf(13));
        types.put("DOUBLE", String.valueOf(7));
        types.put("FLOAT", String.valueOf(6));
        types.put("INPUTSTREAM", String.valueOf(12));
        types.put("INT", String.valueOf(4));
        types.put("INTEGER", String.valueOf(4));
        types.put("BIGINTEGER", String.valueOf(8));
        types.put("LONG", String.valueOf(5));
        types.put("OBJECT", String.valueOf(17));
        types.put("SHORT", String.valueOf(3));
        types.put("STRING", String.valueOf(16));
        types.put("TIMESTAMP", String.valueOf(15));
        types.put("TIME", String.valueOf(14));
        types.put("SERIALBLOB", String.valueOf(19));
        types.put("SERIALCLOB", String.valueOf(20));
        typeMap = new HashMap();
        typeMap.put(String.class, 12);
        typeMap.put(BigInteger.class, -5);
        typeMap.put(SerialBlob.class, 2004);
        typeMap.put(SerialClob.class, 2005);
        typeMap.put(Boolean.class, 16);
        typeMap.put(Boolean.TYPE, 16);
        Integer number = 2;
        typeMap.put(Float.class, number);
        typeMap.put(Float.TYPE, number);
        typeMap.put(Double.class, number);
        typeMap.put(Double.TYPE, number);
        typeMap.put(BigDecimal.class, number);
        typeMap.put(Long.TYPE, number);
        typeMap.put(Long.class, number);
        typeMap.put(Integer.class, 4);
        typeMap.put(Integer.TYPE, 4);
        typeMap.put(Date.class, 91);
        typeMap.put(java.util.Date.class, 91);
        typeMap.put(Time.class, 92);
        typeMap.put(Timestamp.class, 93);
    }

    private ConvertUtil() {
    }

    public static int getType(Object obj) {
        if (obj == null) {
            return 1;
        } else {
            Class cls = obj.getClass();
            return cls.isEnum() ? 21 : getType(obj.getClass());
        }
    }

    public static String getClassSimpleName(Class cls) {
        String name = cls.getName();
        int index = name.lastIndexOf(46);
        if (index > 0) {
            name = name.substring(index + 1);
        }

        return name;
    }

    public static int getType(Class cls) {
        if (cls == null) {
            return 1;
        } else if (cls.isEnum()) {
            return 21;
        } else {
            String typeValue = (String)types.get(getClassSimpleName(cls).toUpperCase());
            return typeValue != null ? Integer.parseInt(typeValue) : 17;
        }
    }

    private static void typeProblem(int unexpectedType, int expectedType, boolean getter) {
        throw new ClassCastException("不支持的类型转换");
    }

    public static BigDecimal toBigDecimal(Object object) {
        int type = getType(object);
        switch (type) {
            case 0:
            case 1:
                return new BigDecimal(0);
            case 2:
                return new BigDecimal(((Byte)object).longValue());
            case 3:
                return new BigDecimal(((Short)object).longValue());
            case 4:
                return new BigDecimal(String.valueOf(object));
            case 5:
                return BigDecimal.valueOf((Long)object, 0);
            case 6:
                return new BigDecimal(String.valueOf(object));
            case 7:
                return new BigDecimal(String.valueOf(object));
            case 8:
                return BigDecimal.valueOf(((BigInteger)object).longValue(), 0);
            case 9:
            case 12:
            case 17:
            case 18:
            case 19:
            case 20:
            default:
                typeProblem(type, 10, true);
                return null;
            case 10:
                return (BigDecimal)object;
            case 11:
                return new BigDecimal((Boolean)object ? 1 : 0);
            case 13:
                return BigDecimal.valueOf(((java.util.Date)object).getTime());
            case 14:
                return BigDecimal.valueOf(((Time)object).getTime());
            case 15:
                return BigDecimal.valueOf(((Timestamp)object).getTime());
            case 16:
                String stringVal = (String)object;
                return stringVal != null && stringVal.length() != 0 ? new BigDecimal(stringVal) : ZEROBIGDECIMAL;
            case 21:
                return new BigDecimal(((Enum)object).ordinal());
        }
    }

    public static Boolean toBoolean(Object object) {
        int type = getType(object);
        switch (type) {
            case 0:
            case 1:
                return Boolean.FALSE;
            case 2:
                return ((Byte)object).longValue() != 0L;
            case 3:
                return ((Short)object).longValue() != 0L;
            case 4:
                return (Integer)object != 0;
            case 5:
                return (Long)object != 0L;
            case 6:
                return ((Float)object).compareTo(ZEROFLOAT) != 0;
            case 7:
                return ((Double)object).compareTo(ZERODOUBLE) != 0;
            case 8:
                return ((BigInteger)object).intValue() != 0;
            case 9:
            case 12:
            default:
                typeProblem(type, 11, true);
                return Boolean.FALSE;
            case 10:
                return ((BigDecimal)object).longValue() != 0L;
            case 11:
                return (Boolean)object;
            case 13:
                return object != null;
            case 14:
                return object != null;
            case 15:
                return object != null;
            case 16:
                String stringVal = (String)object;
                boolean tmpValue = stringVal == null || stringVal.length() == 0 || "0".equals(stringVal) || "false".equalsIgnoreCase(stringVal);
                return !tmpValue;
        }
    }

    public static Byte toByte(Object object) {
        int type = getType(object);
        switch (type) {
            case 0:
            case 1:
                return null;
            case 2:
                return (Byte)object;
            case 3:
                return ((Short)object).byteValue();
            case 4:
                return ((Integer)object).byteValue();
            case 5:
                return ((Long)object).byteValue();
            case 6:
                return ((Float)object).byteValue();
            case 7:
                return ((Double)object).byteValue();
            case 8:
                return ((BigInteger)object).byteValue();
            case 9:
            case 12:
            default:
                typeProblem(type, 2, true);
                return null;
            case 10:
                return ((BigDecimal)object).byteValue();
            case 11:
                return Integer.valueOf((Boolean)object ? 1 : 0).byteValue();
            case 13:
                return Long.valueOf(((java.util.Date)object).getTime()).byteValue();
            case 14:
                return Long.valueOf(((Time)object).getTime()).byteValue();
            case 15:
                return Long.valueOf(((Timestamp)object).getTime()).byteValue();
            case 16:
                String stringVal = (String)object;
                if (StringUtil.isNotEmpty(stringVal)) {
                    try {
                        return stringVal.getBytes("UTF-8")[0];
                    } catch (UnsupportedEncodingException var4) {
                        throw new RuntimeException(var4);
                    }
                } else {
                    return null;
                }
        }
    }

    public static byte[] toByteArray(Object object) {
        return (byte[])object;
    }

    public static java.util.Date toDate(Object value) {
        if (value == null) {
            return null;
        } else {
            long time = 0L;
            if (value instanceof Timestamp) {
                time = ((Timestamp)value).getTime();
            } else {
                if (value instanceof Time) {
                    return (Time)value;
                }

                if (value instanceof java.util.Date) {
                    return (java.util.Date)value;
                }

//                time = ((EcpDate)value).toTimestamp().getTime();
            }

            return new java.util.Date(time);
        }
    }

    public static Date toSqlDate(Object value) {
        if (value == null) {
            return null;
        } else {
            long time = 0L;
            if (value instanceof Timestamp) {
                time = ((Timestamp)value).getTime();
            } else if (value instanceof Time) {
                time = ((Time)value).getTime();
            } else if (value instanceof java.util.Date) {
                time = ((java.util.Date)value).getTime();
            } else if (value instanceof String) {
                try {
                    time = (new SimpleDateFormat("yyyy-MM-dd")).parse((String)value).getTime();
                } catch (ParseException var4) {
                    var4.printStackTrace();
                }
            } else {
//                time = ((EcpDate)value).toTimestamp().getTime();
            }

            return new Date(time);
        }
    }

    public static Double toDouble(Object object) {
        int type = getType(object);
        switch (type) {
            case 0:
            case 1:
                return null;
            case 2:
                return ((Byte)object).doubleValue();
            case 3:
                return ((Short)object).doubleValue();
            case 4:
                return ((Integer)object).doubleValue();
            case 5:
                return ((Long)object).doubleValue();
            case 6:
                return ((Float)object).doubleValue();
            case 7:
                return (Double)object;
            case 8:
                return ((BigInteger)object).doubleValue();
            case 9:
            case 12:
            case 17:
            case 18:
            case 19:
            case 20:
            default:
                typeProblem(type, 7, true);
                return null;
            case 10:
                return ((BigDecimal)object).doubleValue();
            case 11:
                return (double)((Boolean)object ? 1 : 0);
            case 13:
                return Long.valueOf(((java.util.Date)object).getTime()).doubleValue();
            case 14:
                return Long.valueOf(((Time)object).getTime()).doubleValue();
            case 15:
                return Long.valueOf(((Timestamp)object).getTime()).doubleValue();
            case 16:
                String stringVal = (String)object;
                if (StringUtil.isNotEmpty(stringVal)) {
                    return Double.valueOf(stringVal);
                }

                return null;
            case 21:
                return (double)((Enum)object).ordinal();
        }
    }

    public static Float toFloat(Object object) {
        int type = getType(object);
        switch (type) {
            case 0:
            case 1:
                return null;
            case 2:
                return ((Byte)object).floatValue();
            case 3:
                return ((Short)object).floatValue();
            case 4:
                return ((Integer)object).floatValue();
            case 5:
                return ((Long)object).floatValue();
            case 6:
                return (Float)object;
            case 7:
                return ((Double)object).floatValue();
            case 8:
                return ((BigInteger)object).floatValue();
            case 9:
            case 12:
            case 17:
            case 18:
            case 19:
            case 20:
            default:
                typeProblem(type, 6, true);
                return null;
            case 10:
                return ((BigDecimal)object).floatValue();
            case 11:
                return (float)((Boolean)object ? 1 : 0);
            case 13:
                return (float)((java.util.Date)object).getTime();
            case 14:
                return (float)((Time)object).getTime();
            case 15:
                return (float)((Timestamp)object).getTime();
            case 16:
                String stringVal = (String)object;
                if (StringUtil.isNotEmpty(stringVal)) {
                    return Float.valueOf(stringVal);
                }

                return null;
            case 21:
                return (float)((Enum)object).ordinal();
        }
    }

    public static InputStream toInputStream(Object object) {
        return (InputStream)object;
    }

    public static Integer toInteger(Object object) {
        int type = getType(object);
        switch (type) {
            case 0:
            case 1:
                return null;
            case 2:
                return ((Byte)object).intValue();
            case 3:
                return ((Short)object).intValue();
            case 4:
                return (Integer)object;
            case 5:
                return ((Long)object).intValue();
            case 6:
                return ((Float)object).intValue();
            case 7:
                return ((Double)object).intValue();
            case 8:
                return ((BigInteger)object).intValue();
            case 9:
            case 12:
            case 17:
            case 18:
            case 19:
            case 20:
            default:
                typeProblem(type, 4, true);
                return null;
            case 10:
                return ((BigDecimal)object).intValue();
            case 11:
                return (Boolean)object ? 1 : 0;
            case 13:
                return (int)((java.util.Date)object).getTime();
            case 14:
                return (int)((Time)object).getTime();
            case 15:
                return (int)((Timestamp)object).getTime();
            case 16:
                String stringVal = (String)object;
                if (StringUtil.isNotEmpty(stringVal)) {
                    return Integer.valueOf(stringVal);
                }

                return 0;
            case 21:
                return ((Enum)object).ordinal();
        }
    }

    public static int toInt(Object object) {
        int type = getType(object);
        switch (type) {
            case 0:
            case 1:
                return 0;
            case 2:
                return ((Byte)object).intValue();
            case 3:
                return ((Short)object).intValue();
            case 4:
                return (Integer)object;
            case 5:
                return ((Long)object).intValue();
            case 6:
                return ((Float)object).intValue();
            case 7:
                return ((Double)object).intValue();
            case 8:
                return ((BigInteger)object).intValue();
            case 9:
            case 12:
            case 17:
            case 18:
            case 19:
            case 20:
            default:
                typeProblem(type, 4, true);
                return 0;
            case 10:
                return ((BigDecimal)object).intValue();
            case 11:
                return (Boolean)object ? 1 : 0;
            case 13:
                return (int)((java.util.Date)object).getTime();
            case 14:
                return (int)((Time)object).getTime();
            case 15:
                return (int)((Timestamp)object).getTime();
            case 16:
                String stringVal = (String)object;
                if (StringUtil.isNotEmpty(stringVal)) {
                    return 0;
                }

                return Integer.parseInt(stringVal);
            case 21:
                return ((Enum)object).ordinal();
        }
    }

    public static Long toLong(Object object) {
        int type = getType(object);
        switch (type) {
            case 0:
            case 1:
                return null;
            case 2:
                return ((Byte)object).longValue();
            case 3:
                return ((Short)object).longValue();
            case 4:
                return ((Integer)object).longValue();
            case 5:
                return (Long)object;
            case 6:
                return ((Float)object).longValue();
            case 7:
                return ((Double)object).longValue();
            case 8:
                return ((BigInteger)object).longValue();
            case 9:
            case 11:
            case 12:
            default:
                typeProblem(type, 5, true);
                return null;
            case 10:
                return ((BigDecimal)object).longValue();
            case 13:
                return ((java.util.Date)object).getTime();
            case 14:
                return ((Time)object).getTime();
            case 15:
                return ((Timestamp)object).getTime();
            case 16:
                String stringVal = (String)object;
                return StringUtil.isNotEmpty(stringVal) ? Long.valueOf(stringVal) : null;
        }
    }

    public static Short toShort(Object object) {
        int type = getType(object);
        switch (type) {
            case 0:
            case 1:
                return null;
            case 2:
                return ((Byte)object).shortValue();
            case 3:
                return (Short)object;
            case 4:
                return ((Integer)object).shortValue();
            case 5:
                return ((Long)object).shortValue();
            case 6:
                return ((Float)object).shortValue();
            case 7:
                return ((Double)object).shortValue();
            case 8:
                return ((BigInteger)object).shortValue();
            case 9:
            case 11:
            case 12:
            default:
                typeProblem(type, 5, true);
                return null;
            case 10:
                return ((BigDecimal)object).shortValue();
            case 13:
                return (short)((int)((java.util.Date)object).getTime());
            case 14:
                return (short)((int)((Time)object).getTime());
            case 15:
                return (short)((int)((Timestamp)object).getTime());
            case 16:
                String stringVal = (String)object;
                return StringUtil.isNotEmpty(stringVal) ? Short.valueOf(stringVal) : null;
        }
    }

    public static String toString(Object object) {
        return object == null ? null : String.valueOf(object);
    }

    public static Timestamp toTimestamp(Object value) {
        if (value == null) {
            return null;
        } else {
            long time = 0L;
            if (value instanceof Timestamp) {
                return (Timestamp)value;
            } else {
                if (value instanceof Time) {
                    time = ((Time)value).getTime();
                } else if (value instanceof java.util.Date) {
                    time = ((java.util.Date)value).getTime();
                }
//                else if (value instanceof String) {
//                    time = (new EcpDate((String)value)).toTimestamp().getTime();
//                } else {
//                    time = ((EcpDate)value).toTimestamp().getTime();
//                }

                return new Timestamp(time);
            }
        }
    }

    public static Time toTime(Object value) {
        if (value == null) {
            return null;
        } else {
            long time = 0L;
            if (value instanceof Timestamp) {
                time = ((Timestamp)value).getTime();
            } else if (value instanceof java.util.Date) {
                time = ((java.util.Date)value).getTime();
            } else {
                if (value instanceof Time) {
                    return (Time)value;
                }

//                if (value instanceof String) {
//                    time = (new EcpDate((String)value)).toTimestamp().getTime();
//                } else {
//                    time = ((EcpDate)value).toTimestamp().getTime();
//                }
            }

            return new Time(time);
        }
    }

    public static SerialBlob toBlob(Object value) {
        try {
            if (value instanceof SerialBlob) {
                return (SerialBlob)value;
            } else if (value instanceof byte[]) {
                return new SerialBlob((byte[])value);
            } else {
                SerialBlob blob;
                if (value instanceof InputStream) {
                    InputStream stream = (InputStream)value;
                    byte[] b = new byte[stream.available()];
                    stream.read(b);
                    blob = new SerialBlob(b);
                    return blob;
                } else {
                    blob = new SerialBlob(EMPTYBYTES);
                    blob.setBytes(0, toString(value).getBytes());
//                    blob.setAsString(toString(value));
                    return blob;
                }
            }
        } catch (Exception var4) {
            throw new ClassCastException("toBlob失败");
        }
    }

    public static SerialClob toClob(Object value) {
        try {
            if (value instanceof SerialClob) {
                return (SerialClob)value;
            } else {
                SerialClob clob = new SerialClob(EMPTYCHARS);
                clob.setString(0, toString(value));
//                clob.setAsString(toString(value));
                return clob;
            }
        } catch (Exception var3) {
            throw new ClassCastException("toBlob失败");
        }
    }

//    public static <T> T toEnum(Object obj, Class<T> clazz) {
//        try {
//            if (obj instanceof String) {
//                String name = (String)obj;
//                if (name.length() == 0) {
//                    return null;
//                }
//
//                return Enum.valueOf(clazz, name);
//            }
//
//            if (obj instanceof Number) {
//                int ordinal = ((Number)obj).intValue();
//                Method method = clazz.getMethod("values");
//                Object[] values = (Object[])method.invoke((Object)null);
//                Object[] var8 = values;
//                int var7 = values.length;
//
//                for(int var6 = 0; var6 < var7; ++var6) {
//                    Object value = var8[var6];
//                    Enum e = (Enum)value;
//                    if (e.ordinal() == ordinal) {
//                        return (T) e;
//                    }
//                }
//            }
//        } catch (Exception var10) {
//            throw new ClassCastException("can not cast to : " + clazz.getName());
//        }
//        throw new ClassCastException("can not cast to : " + clazz.getName());
//    }

//    public static Object toClassObject(Object instance, Class targetClass) throws ClassNotFoundException {
//        if (instance == null) {
//            return targetClass.isPrimitive() ? ClassUtil.getPrimitiveTypeDefaultObject(targetClass) : null;
//        } else {
//            Class srcClass = instance.getClass();
//            if (srcClass == targetClass) {
//                return instance;
//            } else if (targetClass == Class.class && instance instanceof String) {
//                try {
//                    return Class.forName(toString(instance));
//                } catch (ClassNotFoundException var4) {
//                    throw new ClassNotFoundException("类找不到");
//                }
//            } else {
//                int type = getType(targetClass);
//                switch (type) {
//                    case 2:
//                        return toByte(instance);
//                    case 3:
//                        return toShort(instance);
//                    case 4:
//                        return toInteger(instance);
//                    case 5:
//                        return toLong(instance);
//                    case 6:
//                        return toFloat(instance);
//                    case 7:
//                        return toDouble(instance);
//                    case 8:
//                    case 9:
//                    default:
//                        return instance;
//                    case 10:
//                        return toBigDecimal(instance);
//                    case 11:
//                        return toBoolean(instance);
//                    case 12:
//                        return toInputStream(instance);
//                    case 13:
//                        return toDate(instance);
//                    case 14:
//                        return toTime(instance);
//                    case 15:
//                        return toTimestamp(instance);
//                    case 16:
//                        return toString(instance);
//                    case 17:
//                        return instance;
//                    case 18:
//                        return toByteArray(instance);
//                    case 19:
//                        return toBlob(instance);
//                    case 20:
//                        return toClob(instance);
//                    case 21:
//                        return toEnum(instance, targetClass);
//                }
//            }
//        }
//    }

    public static Class sqlTypeToJavaType(int sqlType) {
        Class result = null;
        switch (sqlType) {
            case -5:
                result = BigInteger.class;
                break;
            case 1:
                result = String.class;
                break;
            case 2:
            case 3:
            case 6:
            case 8:
                result = BigDecimal.class;
                break;
            case 4:
                result = Integer.class;
                break;
            case 12:
                result = String.class;
                break;
            case 16:
                result = Boolean.class;
                break;
            case 91:
                result = java.util.Date.class;
                break;
            case 92:
                result = Time.class;
                break;
            case 93:
                result = Timestamp.class;
                break;
            case 2004:
                result = SerialBlob.class;
                break;
            case 2005:
                result = SerialClob.class;
                break;
            default:
                result = String.class;
        }

        return result;
    }

    public static String getObjectToString(Object object) {
        if (object == null) {
            return null;
        } else {
            Class<?> cls = object.getClass();
            if (cls != Short.TYPE && cls != Short.class && cls != Integer.TYPE && cls != Integer.class) {
                if (cls != Long.TYPE && cls != Long.class && cls != Double.TYPE && cls != Double.class) {
                    if (cls != Float.TYPE && cls != Float.class && cls != BigDecimal.class) {
                        if (cls != BigInteger.class && cls != Boolean.TYPE && cls != Boolean.class) {
                            if (cls != Byte.TYPE && cls != Byte.class && cls != String.class) {
                                if (cls == java.util.Date.class) {
                                    return String.valueOf(((java.util.Date)object).getTime());
                                } else if (cls == Date.class) {
                                    return String.valueOf(((Date)object).getTime());
                                } else {
                                    return cls == Timestamp.class ? String.valueOf(((Timestamp)object).getTime()) : null;
                                }
                            } else {
                                return String.valueOf(object);
                            }
                        } else {
                            return String.valueOf(object);
                        }
                    } else {
                        return String.valueOf(object);
                    }
                } else {
                    return String.valueOf(object);
                }
            } else {
                return String.valueOf(object);
            }
        }
    }

    public static Object getObject(String type, String value) {
        if (StringUtil.isNotEmpty(type)) {
            if (Boolean.class.getName().toUpperCase().equals(type.toUpperCase())) {
                return Boolean.valueOf(value);
            }

            if (Integer.class.getName().toUpperCase().equals(type.toUpperCase())) {
                return Integer.valueOf(value);
            }

            if (BigDecimal.class.getName().toUpperCase().equals(type.toUpperCase())) {
                return new BigDecimal(value);
            }

            if (java.util.Date.class.getName().toUpperCase().equals(type.toUpperCase())) {
                return new java.util.Date(value);
            }

            if (Date.class.getName().toUpperCase().equals(type.toUpperCase())) {
                return new Date((new java.util.Date(value)).getTime());
            }

            if (Timestamp.class.getName().toUpperCase().equals(type.toUpperCase())) {
                return Timestamp.valueOf(value);
            }

            if (String.class.getName().toUpperCase().equals(type.toUpperCase())) {
                return value;
            }
        }

        return null;
    }

    public static boolean checkComparable(Object object) {
        return object != null && Comparable.class.isAssignableFrom(object.getClass());
    }

    public static boolean checkCollection(Object object) {
        return object != null && Collection.class.isAssignableFrom(object.getClass());
    }

    public static int javaTypeToSqlType(Class cls) {
        if (cls.isEnum()) {
            return 4;
        } else {
            Integer result = (Integer)typeMap.get(cls);
            return result == null ? 12 : result;
        }
    }

//    public static <T> T mapToObject(Map<String, Object> map, Class<T> beanClass) {
//        if (map == null) {
//            return null;
//        } else {
//            T obj = null;
//
//            try {
//                obj = beanClass.newInstance();
//                BeanUtils.populate(obj, map);
//                return obj;
//            } catch (Throwable var4) {
//                throw new CastException("E0208.0009", EcpI18nUtil.localizedString("E0208.0009", "can not cast to : {0}", new Object[]{beanClass.getName()}));
//            }
//        }
//    }

//    public static Map<?, ?> objectToMap(Object obj) {
//        if (obj == null) {
//            return null;
//        } else {
//            try {
//                return new BeanMap(obj);
//            } catch (Throwable var2) {
//                throw new CastException("E0208.0009", EcpI18nUtil.localizedString("E0208.0009", "can not cast to : {0}", new Object[]{Map.class.getName()}));
//            }
//        }
//    }
}
